import random
def guess_number_game():
    target_number = random.randint(1,100)
    guess_count = 0
    print("我已经想好了一个 1 到 100 之间的数字，快来猜猜看吧！")
    while True:
        try:
            guess = int(input("请输入你猜的数字(1-100)："))
            if guess < 1 or guess > 100:
                print("请输入 1 到 100 之间的数字!")
                continue
            guess_count += 1
            if guess < target_number:
                print("你猜的数字小了，请再试一次！")
            elif guess > target_number:
                print("你猜的数字大了，请再试一次！")
            else:
                print(f"恭喜你，你猜对了！答案是{target_number}。")
                print("你总共猜了", guess_count, "次！")
                break
        except ValueError:
            print("请输入一个数字！")
guess_number_game()